﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Yammu.Core.MediaManagement
{
    public class ConfiguredMediaPathColl : MarshalByRefObject, IConfiguredMediaPathColl
    {
        List<IConfiguredMediaPath> _includedPaths = new List<IConfiguredMediaPath>();

        List<IConfiguredMediaPath> _excludedPaths = new List<IConfiguredMediaPath>(); 

        #region Implementation of IConfiguredMediaPathColl

        public IList<IConfiguredMediaPath> IncludedPaths
        {
            get { return _includedPaths.AsReadOnly(); }
        }

        public IList<IConfiguredMediaPath> ExcludedPaths
        {
            get { return _excludedPaths.AsReadOnly(); }
        }

        public void IncludePath(IConfiguredMediaPath path)
        {
            List<IConfiguredMediaPath> result = (from p in _includedPaths
                         where (p == path)
                         select p).ToList();

            if( result.Count()==0)
            {
                _includedPaths.Add(new ConfiguredConfiguredMediaPath());

                result.ForEach(item => _excludedPaths.Remove(item));
            }

        }

        public void ExcludePath(IConfiguredMediaPath path)
        {
            List<IConfiguredMediaPath> result = (from p in _excludedPaths
                                       where (p == path)
                                       select p).ToList();

            if (result.Count() == 0)
            {
                _excludedPaths.Add(new ConfiguredConfiguredMediaPath());

                result.ForEach(item => _includedPaths.Remove(item));
            }
        }

        public void SetPaths(List<IConfiguredMediaPath> includedPaths, List<IConfiguredMediaPath> excludedPaths)
        {
            _includedPaths.ForEach(item=>IncludePath(item));
            _excludedPaths.ForEach(item => ExcludePath(item));
        }

        #endregion
    }
}
